﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BCDataCenter;
public partial class ControlUser_ControlInNghiepVuDieuChinhTonKho : System.Web.UI.UserControl
{
    ClassExecute.ClassExecute dt;
    string str = BCDataCenter.Configuration.CurrentConnectionString;
    string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetBindGrid();
            if (Session["DocNo"] != null)
            {
                Session["DocNo"] = null;
            }
        }
        
    }
    void GetBindGrid()
    {
        dt = new ClassExecute.ClassExecute();
        DataTable db = dt.Get_Data_DataTable(str, ref error, "ls_getAdjTrnNoListAtBranchSite", CommandType.StoredProcedure,
            new SqlParameter("@siteCode", Session["sitecode"].ToString()));
        if (db.Rows.Count > 0)
        {
            GridView1.DataSource = db;
            GridView1.DataBind();
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GetBindGrid();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {

            try
            {
                dt = new ClassExecute.ClassExecute();
                GridViewRow grv = ((Control)e.CommandSource).NamingContainer as GridViewRow;
                Session["DocNo"] = grv.Cells[0].Text;
                bool kq = dt.ExecuteSQl_bool(str, CommandType.StoredProcedure, "ls_updatePrintedAdjTrn", ref error,
                    new SqlParameter("@DocNo", grv.Cells[0].Text));
                GetBindGrid();
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append("window.open('" + Globals.ApplicationPath + "WebMaster/Administrator/InNghiepVuDieuChinhTonKho/PrintNVDieuChinhTonKho.aspx','PrintMe', 'height=900px,width=900px,scrollbars=1');");
                ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, this.UpdatePanel1.GetType(), "NewClientScript", sb.ToString(), true);
            }
            catch
            {

            }
        }
    }
}